package cn.kshost.zqyg.manager.scheduled;

import cn.kshost.zqyg.manager.mapper.OrderInfoMapper;
import cn.kshost.zqyg.manager.mapper.OrderStatisticsMapper;
import cn.kshost.zqyg.model.entity.order.OrderStatistics;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;

@Component
@Slf4j
public class OrderStatisticsTask {
    @Autowired
    OrderInfoMapper orderInfoMapper;

    @Autowired
    OrderStatisticsMapper orderStatisticsMapper;

    @Scheduled( cron ="0 0 2 * * *")
    public void orderTotalAmountStatistics() {
        //获取item数据封装
        System.out.println(123);
        LocalDate localDate = LocalDate.now().minusDays(1);
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String date = dateTimeFormatter.format(localDate);
        //统计昨天的订单返回 orderStatistic类型
        OrderStatistics orderStatistic =  orderInfoMapper.selectorderTotalAmountStatistics(date);
        //将数据插入到OrderStatistics
        orderStatisticsMapper.insertorderStatistics(orderStatistic);
    }
}
